//
//  MainController.swift
//  WeiBo001
//
//  Created by ZhiQiang Li on 16/7/19.
//  Copyright © 2016年 ZhiQiang Li. All rights reserved.
//

import UIKit

class MainController: UITabBarController {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let tabBar = CZTabBar()
        tabBar.czDelegate = self
        tabBar.closure = {
            print("强爷点击按钮啦")
        }
        setValue(tabBar, forKey: "tabBar")
        addChildViewController(HomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageController(), title: "消息", imageName: "tabbar_message_center")

        addChildViewController(DiscoverController(), title: "发现", imageName: "tabbar_discover")
               addChildViewController(MyController(), title: "我", imageName: "tabbar_profile")

       
    }
     func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        //设置文字
        vc.title = title;
        //设置图片
       vc.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置渲染方式
       vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //添加到控制器
        
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
    
}
extension  MainController:CZTabBarDelegate{
    func composeButtonClick() {
        print("强爷要点击了")
    }
}